//导入 mongoose
//const { time } = require('@pupbot/core');
const mongoose = require('mongoose');
//创建文档的结构对象
//设置集合中文档的属性以及属性值的类型



// 定义图片的 schema
const imageSchema = new mongoose.Schema({
  url: { 
    type: String,
    default: '' 
  },
  desc:  { 
    type: String,
    default: '' 
  }
});

// 定义评论的 schema，每个评论包含一个或多个图片和一条评论介绍
const commentSchema = new mongoose.Schema({
  goods_id:String,
  text: { 
    type: String,
    default: '' 
  },
  images: [imageSchema]
});

let orderSchema = new mongoose.Schema({
  user_id:{ 
    type:mongoose.Schema.Types.ObjectId,
   
  },
  task_id:{ 
    type:mongoose.Schema.Types.ObjectId,
  
  },
  shopName:String,
  order_id:String,
  buyer:String,
  desc:  { 
    type: String,
    default: '' 
  },
  items:[commentSchema],
  state:Number,
  last_time: Date,
});

//创建模型对象  对文档操作的封装对象
let commontModel = mongoose.model('commont', orderSchema);

//暴露模型对象
module.exports = commontModel;
